package com.company;

public class Test03水仙花数 {
    public static void main(String[] args) {
            for(int i=100;i<200;i++){
                if(hua(i)) {
                    System.out.println(i);
                }else {
                    System.out.println(i+"is not number");
                }
            }
    }

    /**
     * 水仙花数
     * @param x
     * @return
     */
    public static  boolean huaShu(int x){
        boolean flag = false;
        int num1 = x/100;
        int num2 = (x /10)%10;
        int num3 = x % 10;
        //System.out.println("test"+num1+num2+num3);
        if(x == (Math.pow(num1,3) + Math.pow(num2,3) + Math.pow(num3,3))){
            flag = true;
        }
        return flag;
    }
    public static boolean hua(int x){
        char str[]=String.valueOf(x).toCharArray();
        int tmp = 0;
        for(int i=0;i<str.length;i++){
            tmp = (int) (tmp + Math.pow(Integer.valueOf(String.valueOf(str[i])),3));
        }
        if(tmp==x){
            return true;
        }
        return false;
    }
}
